package com.kb.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.kb.entity.User;
import com.kb.mapper.mysql.UserDao;
import com.kb.service.UserService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@DS("master")
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    @Value("${login.userName:admin}")
    private String name;
    @Value("${login.password:123456}")
    private String password;

    @Override
    public User loing(String userName, String userPassword) {
        //查表方式
        Map<String, Object> map = new HashMap<>();
        map.put("user_name", userName);
        map.put("password", userPassword);
        List<User> users = userDao.selectByMap(map);
        if (CollectionUtils.isEmpty(users)){
            return null;
        }
        return users.get(0);
//        if (Objects.equals(userName,name) && Objects.equals(userPassword,password)){
//            User user = new User();
//            user.setUserName(name);
//            user.setPassword(password);
//            return user;
//        }
//        return null;
    }

    @Override
    public List<User> getUserList() {
        return userDao.selectList(null);
    }

}
